#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    :  
# @function: 
# @version :


import time
from concurrent.futures import ThreadPoolExecutor, wait


def get_html(time_attr):
    time.sleep(time_attr)
    print(f'get page {time_attr} success')
    return time_attr


# 创建线程池对象
executor = ThreadPoolExecutor(max_workers=2)

# 批量提交任务并获取已经执行成功的task的返回值
time_attr_list = [3, 2, 5, 4]

all_tasks = [executor.submit(get_html, time_attr) for time_attr in time_attr_list]
# wait需要在concurrent.futures中导入
wait(all_tasks)  # 等待线程池中的任务完成后主线程向下执行
print('主线程执行')
